www.gusucode.com > 超声波测量以及形成图像 对相关信号进行模拟仿真 > 超声波测量以及形成图像 对相关信号进行模拟仿真/digital holograpy/prog/SCfilter.m

    function [ b ] = SCfilter( mask,a,it,varargin )
%SCfilter Sine / Cosine Filter for the phase fringe pattern
%  Syntax:
%  [ b ] = SCfilter( mask,a,it );
%  [ b ] = SCfilter( mask,a,it,'PropertyName','PropertyValue',... );
%
%  a : the data to be filtered
%  mask : the mask to filter a
%  it : iteration time
%  this program calls filter2 'it' times to filter a phase fringe pattern
%--------------------------------------------------------------------------
%  PropertyName and PropertyValue:
%
%  shape             {full} | same | valid
%  the output shape of the function filter2 in each iteration step
%  See filter2
%  
%  recalculation     {on} | off
%  recalculate the phase after each filter step and calculate the
%  sine and cosine fringe patterns from this new phase before the
%  next filter step is initiated, see reference [1]
%       on  - recalculate
%       off - do not recalculate
%  ------------------------------------------------------------------------
%  Reference:
%  [1]
%  Hubert A.Aebischer, Stephan Waldner. A simple and effective method for 
%  filtering speckle-interferometric phase fringe patterns. Optics
%  Communications. 162,1999:205–210
%  ------------------------------------------------------------------------
error(nargchk(3,7,nargin))
for n=1:length(varargin)
    if ~ischar(varargin{n})
        error('Property names and values must be characters')
    end
end
%  ----------------------construct the property array----------------------
parray=[0,0];                                                               % initialize the property array, the property array
                                                                            % is used to store the property specified by the user
property=struct('name',{'shape','recalculation'});                          % construct the property structure,
property(1).value={'full','same','valid',''};                               % which stores all possible properties
property(2).value={'on','off',''};
for l=1:2:length(varargin)
    namefound=0;
    valuefound=0;
    m=0;
    n=0;
    while ~namefound && m<length(parray)
        m=m+1;
        if strcmp(varargin{l},property(m).name)
            namefound=1;
        end
    end
    while namefound && ~valuefound && n<length(property(m).value)
        n=n+1;
        if strcmp(varargin{l+1},property(m).value{n})
            valuefound=1;
            parray(m)=n;
        end
    end
    if namefound==0
        error('wrong property name')
    elseif valuefound==0
        error('wrong property value')
    end
end
%  ------------------------------------------------------------------------
b=a;
if it==0
    return
end
[M1,N1]=size(mask);
[M2,N2]=size(a);
if rem(M1,2)*rem(N1,2)==0
    warning('the size of the mask should be odd')
end
shapevalues={'full','full','same','valid','full'};
sine=sin(b);
cosine=cos(b);
for t=1:it
    sine=filter2(mask,sine,shapevalues{parray(1)+1});
    cosine=filter2(mask,cosine,shapevalues{parray(1)+1});
    if parray(2)~=2
        b=angle(cosine+i*sine);
        sine=sin(b);
        cosine=cos(b);
    end
end
b=angle(cosine+i*sine);
if parray(1)==0 || parray(1)==1 || parray(1)==4
    b=paste(zeros(M2,N2),b);
end